/*
 * @Author: xiaosihan
 * @Date: 2021-04-10 18:25:35
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2021-05-04 21:21:00
 */

import { Euler } from "three";
import Transition from "./Transition";

// 待缓动效果的3d顶点
export default class TransitionEuler extends Euler {

    constructor(_x = 0, _y = 0, _z = 0) {
        super(_x, _y, _z);

        this._transition = new Transition({ _x, _y, _z });

        Object.defineProperties(this, {
            _x: {
                set(v) {
                    this._transition._x = v;
                },
                get() {
                    return this._transition._x;
                }
            },
            _y: {
                set(v) {
                    this._transition._y = v;
                },
                get() {
                    return this._transition._y;
                }
            },
            _z: {
                set(v) {
                    this._transition._z = v;
                },
                get() {
                    return this._transition._z;
                }
            },
        });

    }

    _transition!: Transition;

    setDuration(duration: number = 500) {
        this._transition.setDuration(duration);
        return this;
    }

    // 设置起始位置
    setStart({ x: _x, y: _y, z: _z }: { [key: string]: number } | Euler = {}) {
        this._transition.setStart({ _x, _y, _z });
        return this;
    }

    // 设置结束位置
    setEnd({ x: _x, y: _y, z: _z }: { [key: string]: number } | Euler = {}) {
        this._transition.setEnd({ _x, _y, _z });
        return this;
    }

    // 设置起始位置
    reset({ x: _x, y: _y, z: _z }: { [key: string]: number } | Euler = {}) {
        this._transition.reset({ _x, _y, _z });
        return this;
    }

    setBezier(bezier: [number, number, number, number] = [0.8, 0, 0.2, 1]) {
        this._transition.setBezier(bezier);
        return this;
    }

    isDone() {
        return this._transition.isDone();
    }
}